/*
 * @lc app=leetcode.cn id=1 lang=swift
 *
 * [1] 两数之和
 给定 nums = [2, 7, 11, 15], target = 9
 
 因为 nums[0] + nums[1] = 2 + 7 = 9
 */

class Solution1 {
    func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
        var dict: [Int: Int] = [:]
        for index in 0..<nums.count {
            let item = nums[index]
            if let i = dict[target - item]   {
                return [index, i]
            } else {
                dict[item] = index
            }
        }
        return []
    }
    
    static func test() {
        let nums = [2,7,11,15]
        let solution = Solution1()
        let result = solution.twoSum(nums, 9)
        print(result)
    }
}
// @lc code=end

